package cn.iocoder.yudao.framework.business.basic.pojo.po;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.OrderBy;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import java.io.Serializable;
import java.util.Map;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * 带主键的数据库表实体，由子类继承
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民
 */
@SuppressWarnings("unused")
@Data
public abstract class AbstractEntity<T extends Serializable> implements TableEntity {

    /**
     * 唯一编号，默认使用雪花算法生成的编号
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @OrderBy
    private T id;

    @Override
    public String toString() {
        return getClass().getName() + ":" + getId();
    }

    public Map<String, Object> toMap() {
        return JSONUtil.parse(this, JSONConfig.create()).toBean(new TypeReference<>() {
        }.getType());
    }

}
